﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.ComponentModel;

namespace MixScriptWeb.control
{
    public partial class WebUserControl1 : System.Web.UI.UserControl, ICallbackEventHandler
    {

       

        [DefaultValue("")]
        public string Text
        {
            get {
                if (_uppercase)
                {
                    //if (_readonly)
                    //{
                    //    return hf.Value.ToUpper();
                    //}
                    //else
                    //{
                    //    return txt.Text.ToUpper();
                    //}
                     return txt.Text.ToUpper();
                }
                else
                {
                    if (_readonly)
                    {
                        //return hf.Value.ToString();
                        return txt.Text;
                    }
                    else
                    {
                        return txt.Text;
                    }                    
                }
            }
            set
            {
                if (_uppercase)
                {
                    txt.Text = value.ToUpper();
                 //   hf.Value = value.ToUpper();
                }
                else
                {
                    txt.Text = value;
                   // hf.Value = value;
                }
            }
        }


        public TextBox Tbx
        {
            get { return txt; }
        }
        public Unit tWidht
        {
            get { return txt.Width; }
            set { txt.Width = value; }
        }
        [DefaultValue("")]
        public string tooltip { get; set; }

        private bool _readonly = false;
        public bool ReadOnly
        {
            get { return _readonly; }
            set
            {
                _readonly = value;
                if (_readonly)
                {
                   // txt.Attributes.Add("readonly", "readonly");
                 //   txt.Attributes.Add("readonly", "readonly");
                }
                //txt.ReadOnly = value;
            }
        }

        private bool _uppercase = true;
        public bool UpperCase
        {
            get
            {
              
                return _uppercase; }
            set
            {
                _uppercase = value;
              
            }
        }
        private InqMethod _inquiryMethod = InqMethod.Equal;

        public InqMethod InquiryMethod
        {
            get { return _inquiryMethod; }
            set { _inquiryMethod = value; }
        }

        private bool _usequote = true;

        public bool UseQuote
        {
            get { return _usequote; }
            set { _usequote = value; }
        }

        private bool _isPassword = false;
        public bool isPassword
        {
            get
            {
                return _isPassword;
            }
            set
            {
                if (value)
                {
                    txt.TextMode = TextBoxMode.Password;
                    
                }
                else
                {
                    txt.TextMode =TextBoxMode.SingleLine;
                }
            }
        }

        private bool _isvalid = true;
        public bool isvalid
        {
            get
            {
                return _isvalid;
            }
            set
            {

                imgError.Visible = !value;
                _isvalid = value;
            }
        }
        private bool _showFind = false;
        public bool showFind
        {
            get
            {
                return _showFind;
            }
            set
            {
                imgFind.Visible = value;
                _showFind = value;
            }
        }

        public bool AllowNull { get; set; }



        public WebUserControl1()
        {
            //   tooltip = "";
            //     isvalid = true;
            // initState();

           // imgFind.Attributes.Add("onclick", "return browseitem('" + Page.Form.ClientID + "', '" + this.ClientID + "_txt');");
            

        }



        bool chekvalid()
        {
            try
            {
                if (!AllowNull)
                {
                    if (txt.Text.Trim() == string.Empty)
                    {
                        isvalid = false;
                        return false;
                    }
                }

                return true;
            }
            catch (Exception ex)
            {

                throw ex;
            }
        }

        void initState()
        {
            //imgError.ToolTip = tooltip;
            //if (isvalid)
            //{
            //    imgError.Visible = false;
            //}
            //else
            //{
            //    imgError.Visible = true;
            //}
            //if (showFind)
            //{
            //    imgFind.Visible = true;
            //}
            //else
            //{
            //    imgFind.Visible = false;
            //}

        }

        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                //imgFind.OnClientClick=
                //initState();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }



        #region ICallbackEventHandler Members

        public string GetCallbackResult()
        {
            throw new NotImplementedException();
        }

        public void RaiseCallbackEvent(string eventArgument)
        {
            throw new NotImplementedException();
        }

        #endregion


       // public EventArgs findclick();
        public virtual void imgFind_Click(object sender, ImageClickEventArgs e)
        {

          //  txt.Text = "dari dalem";
        }
    }

    

      
}